<?php

namespace App\Service\Coin;

use App\Model\CallBase;
use App\Model\CoinLog;
use App\Service\BaseService;

use App\Constants\ErrorCode;

/**
 * 我的收支明细列表
 */
class CoinDetailListService extends BaseService
{
    public function handle()
    {
	$userId = $this->getUserId();
        $page = $this->request->input('page', 1);
        //虚拟币账户信息
        $list = CoinLog::getDetailList($userId, $page, $this->pageNum);

        //筛选天天福利流水
        $freeLogs = array_filter($list, function ($var) {
            return ($var['from'] == CoinLog::FROM_DAILY_FREE);
        });
        $freeOrderIds = array_column($freeLogs, 'order_id');
        $callsInfo = CallBase::pickCallTypeFromOrder($freeOrderIds);

        $ret = ['list' => []];
        foreach ($list as $item) {
            $ret['list'][] = CoinLog::buildItem($item, $callsInfo);
	}
	//return $this->setError(ErrorCode::CHAT_BLACK_LMT, $ret);
        // log_user_result($userId, $ret);
        return $ret;
    }
}
